home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Programming / GMS / GMSDev / Source / E / Demos / MultiLine.e < prev    next >
Encoding:
Text File  |  1998-05-14  |  3.9 KB  |  144 lines

  1. /* GMS-example
  2.  * Name: MultiLine.e
  3.  * Type: Blitter example (based on Bounceline.e/c)
  4.  * Version: 1.0
  5.  * Author: G. W. Thomassen (0000272e@lts.mil.no)
  6.  */
  7.  
  8. MODULE 'gms/dpkernel','gms/dpkernel/dpkernel','gms/graphics/pictures',
  9.        'gms/screens','gms/system/register','gms/system/modules','gms/graphics/pictures',
  10.        'gms/graphics/screens','gms/graphics/blitter','gms/blitter'
  11.  
  12. ENUM NONE,ERR_LIB,ERR_SCR,ERR_SMOD,ERR_BMOD,ERR_JOY
  13.  
  14. PROC main() HANDLE
  15.   DEF scr=NIL:PTR TO screen,
  16.       scrmodule=NIL:PTR TO module,
  17.       bltmodule=NIL:PTR TO module,
  18.       sx,sy,ex,ey,state,up=0,
  19.       dsx,dsy,dex,dey,col,count=0
  20.  
  21.   DEF colours[10]:ARRAY OF LONG
  22.  
  23.   colours := [ $00ff0000, $0000ff00, $000000ff, $00ff00ff, $0000ff77,
  24.                $00ffff00, $004488aa, $0000ffff, $00999999, $00ffffff ]:LONG
  25.  
  26.  
  27.   IF (dpkbase:=OpenLibrary('GMS:libs/dpkernel.library',0))=NIL THEN Raise(ERR_LIB)
  28.  
  29.   IF (bltmodule:=Init([TAGS_MODULE,NIL,     ->blitter-module
  30.       MODA_NUMBER,    MOD_BLITTER,
  31.       MODA_TABLETYPE, JMP_AMIGAE,
  32.       TAGEND], NIL))=NIL THEN Raise(ERR_BMOD)
  33.       bltbase := bltmodule.modbase
  34.  
  35.   IF (scrmodule:=Init([TAGS_MODULE,NIL,       ->screen-module
  36.       MODA_NUMBER,    MOD_SCREENS,
  37.       MODA_TABLETYPE, JMP_AMIGAE,
  38.       TAGEND], NIL))=NIL THEN Raise(ERR_SMOD)
  39.       scrbase:=scrmodule.modbase
  40.  
  41.   col := colours[SlowRandom(10)] -> Set the first colour (+$010101 to
  42.                                  ->   prevent black colour)
  43.  
  44.   IF (scr:=Init([TAGS_SCREEN, NIL,
  45.        GSA_ScrMode, SM_HIRES + SM_LACED,
  46.        GSA_Width,   640,
  47.        GSA_Height,  512,
  48.        GSA_Attrib,  SCR_DBLBUFFER,   -> Two frames (Doublebuffering)
  49.          GSA_BitmapTags, NIL,
  50.          BMA_Palette,    [PALETTE_ARRAY,2,$000000,$000000],
  51.          TAGEND,NIL,
  52.        TAGEND],NIL))=NIL THEN Raise(ERR_SCR)
  53.  
  54.   -> Calculate start values..
  55.   sx:=SlowRandom(scr.width);  dsx:=-1
  56.   sy:=SlowRandom(scr.height); dsy:=2
  57.   ex:=SlowRandom(scr.width);  dex:=3
  58.   ey:=SlowRandom(scr.height); dey:=1
  59.  
  60.   -> Display the screen
  61.   Show(scr)
  62.  
  63.   REPEAT
  64.     -> Calculate new values
  65.     sx:=sx+dsx
  66.     sy:=sy+dsy
  67.     ex:=ex+dex
  68.     ey:=ey+dey
  69.  
  70.     -> Check if screen limits are exceeded
  71.     IF sx<0; sx:=0; dsx:=-dsx; ENDIF
  72.     IF sy<0; sy:=0; dsy:=-dsy; ENDIF
  73.     IF ex<0; ex:=0; dex:=-dex; ENDIF
  74.     IF ey<0; ey:=0; dey:=-dey; ENDIF
  75.  
  76.     IF (sx>(scr.width))
  77.       sx:=scr.width-2
  78.       dsx:=-dsx
  79.     ENDIF
  80.     IF (sy>(scr.height))
  81.       sy:=scr.height-2
  82.       dsy:=-dsy
  83.     ENDIF
  84.     IF (ex>(scr.width))
  85.       ex:=scr.width-2
  86.       dex:=-dex
  87.     ENDIF
  88.     IF (ey>(scr.height))
  89.       ey:=scr.height-2
  90.       dey:=-dey
  91.     ENDIF
  92.  
  93.     -> Colour fading
  94.     IF up=0 THEN state := PaletteToColour(scr,state,3,1,1,scr.bitmap.palette+8,col)
  95.     IF up=2 THEN state := ColourMorph(scr,state,1,1,1,col,$000000)
  96.  
  97.     -> Set up new color when the last was reached..
  98.     IF state=NIL
  99.       IF up=0
  100.         up:=1
  101.       ELSEIF up=1
  102.         INC count
  103.         IF count>700
  104.           count:=0
  105.           up:=2
  106.         ENDIF
  107.       ELSE
  108.         -> Clear both frames and set up a new colour value
  109.         Clear(scr.bitmap); WaitAVBL()
  110.         SwapBuffers(scr); WaitAVBL()
  111.         Clear(scr.bitmap)
  112.         col:=colours[SlowRandom(10)]
  113.         up:=0
  114.       ENDIF
  115.     ENDIF
  116.     -> Draw the line and put the frame in front.
  117.    DrawLine(scr.bitmap,sx,sy,ex,ey,1,$FFFFFFFF)
  118.     WaitAVBL()
  119.     SwapBuffers(scr)
  120.   UNTIL Mouse()=1       -> You should use the Joy-module instead.
  121.  
  122.   -> No error..
  123.   Raise(NONE)
  124.  
  125. EXCEPT DO
  126.  
  127.   -> Close down everything
  128.   IF scr THEN Free(scr)
  129.   IF scrmodule THEN Free(scrmodule)
  130.   IF bltmodule THEN Free(bltmodule)
  131.   CloseDPK()
  132.  
  133.   -> Report errors..
  134.   SELECT exception
  135.   CASE ERR_LIB; WriteF('Couldn\at open "dpkernel.library"\n')
  136.   CASE ERR_SMOD; WriteF('Couldn\at initialize screen-module\n')
  137.   CASE ERR_SCR; WriteF('Couldn\at open screen\n')
  138.   CASE ERR_BMOD; WriteF('Couldn\at initialize blitter-module\n')
  139.   ENDSELECT
  140.  
  141.   -> End with the return code 0, a good way to end programs..
  142.   CleanUp(0)
  143. ENDPROC
  144.